export PYTHONPATH := $(SUMOPATH)/tools:$(TOP)/traci_interface

###
# Variables used by gtest targets
###
TEST_CFLAGS := -g -pthread

PYTHON_HEADER=/usr/include/python2.7

PYTHON_INTERFACE_NAME=feature_test
PYTHON_LIB=_$(PYTHON_INTERFACE_NAME).so
PYTHON_INTERFACE_FILE=$(PYTHON_INTERFACE_NAME).i

GTEST := $(TOP)/libs/gtest-1.6.0
GTESTLIB := $(GTEST)/lib/.libs
GTESTINCLUDE := $(GTEST)/include

GTEST_MAIN := $(TOP)/test/unit/gtest_main.o

INCLUDES += -I$(GTESTINCLUDE)
LIBS += -L$(GTESTLIB) -lgtest

ifdef FEATURE

ifdef PYTHON
TESTS_FILES := $(addsuffix _feature_py, $(TESTS))
else
TESTS_FILES := $(addsuffix _feature, $(TESTS))
endif
else
TESTS_FILES := $(addsuffix _gtest, $(TESTS))
endif

EXE := $(TESTS_FILES)

.PHONE: runtests buildtests

pyunit:
	@echo "\nPYUNIT - Running $(PYTHON_TESTS)" 
	python -m unittest $(PYTHON_TESTS)
	@echo "\n"
	
runtests: $(TESTS_FILES)
	@for exe in $(TESTS_FILES); do \
		echo "\nGTEST - Running $$exe"; \
		./$$exe; \
		echo "\n"; \
	done
	
%_gtest: $(GTEST_MAIN) $(OBJECTS)
	g++ $(TEST_CFLAGS) $(OBJECTS) $< -o $@ $(LIBS)
	
%_feature: $(OBJECTS)
	g++ $(TEST_CFLAGS) $< -o $@ $(LIBS)
	
%_feature_py: $(OBJECTS)
	$(info Compiling python test case)
	swig -c++ -python $(PYTHON_INTERFACE_FILE)
	g++ -c -fPIC $(TEST_CFLAGS) $(PYTHON_INTERFACE_NAME)_wrap.cxx -o $(PYTHON_INTERFACE_NAME)_wrap.o $(INCLUDES) -I$(PYTHON_HEADER)
	g++ -shared $(TEST_CFLAGS) $(OBJECTS) $(PYTHON_INTERFACE_NAME)_wrap.o $(LIBS) -o $(PYTHON_LIB) 
